]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
Add an active property to ShellButtonBox
authorOwen W. Taylor <otaylor@fishsoup.net>
Sat, 29 Aug 2009 16:00:20 +0000 (12:00 -0400)
committerOwen W. Taylor <otaylor@fishsoup.net>
Sat, 29 Aug 2009 19:20:18 +0000 (15:20 -0400)
Add an 'active' property to ShellButtonBox. This allows ShellButtonBox
to be used as a "toggle button". It's up the application to connect
it to the ::activate signal; there's no default handling of this.

(It's seldom that the only time you want to toggle a toggle button
through the user interface, so you need some connection to the backend
data store in any case. Removing the default handling all-together
prevents weird interactions.)

When we have built-in styling for ShellButtonBox the 'active' state
would be one of the elements that would be affect the styling.

http://bugzilla.gnome.org/show_bug.cgi?id=593502

src/shell-button-box.c

index 16c46590330972a4427a7e750af5068c76672e68..25808a45a645d8f5e19f44607f6c677e58e8349d 100644 (file)
@@ -14,6 +14,7 @@
 G_DEFINE_TYPE(ShellButtonBox, shell_button_box, BIG_TYPE_BOX);
 
 struct _ShellButtonBoxPrivate {
+  gboolean active;
   gboolean held;
   gboolean hover;
   gboolean pressed;
@@ -29,12 +30,23 @@ enum
 enum {
   PROP_0,
 
+  PROP_ACTIVE,
   PROP_HOVER,
   PROP_PRESSED,
 };
 
 static guint shell_button_box_signals [LAST_SIGNAL] = { 0 };
 
+static void
+set_active (ShellButtonBox  *box,
+            gboolean         active)
+{
+  if (box->priv->active == active)
+    return;
+  box->priv->active = active;
+  g_object_notify (G_OBJECT (box), "active");
+}
+
 static void
 set_hover (ShellButtonBox  *box,
            gboolean         hover)
@@ -150,8 +162,13 @@ shell_button_box_set_property(GObject         *object,
                               const GValue    *value,
                               GParamSpec      *pspec)
 {
+  ShellButtonBox *box = SHELL_BUTTON_BOX (object);
+
   switch (prop_id)
     {
+    case PROP_ACTIVE:
+      set_active (box, g_value_get_boolean (value));
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -168,6 +185,9 @@ shell_button_box_get_property(GObject         *object,
 
   switch (prop_id)
     {
+    case PROP_ACTIVE:
+      g_value_set_boolean (value, box->priv->active);
+      break;
     case PROP_PRESSED:
       g_value_set_boolean (value, box->priv->pressed);
       break;
@@ -204,6 +224,21 @@ shell_button_box_class_init (ShellButtonBoxClass *klass)
                   g_cclosure_marshal_VOID__VOID,
                   G_TYPE_NONE, 0);
 
+  /**
+   * ShellButtonBox:active
+   *
+   * The property allows the button to be used as a "toggle button"; it's up to the
+   * application to update the active property in response to the activate signal;
+   * it doesn't happen automatically.
+   */
+  g_object_class_install_property (gobject_class,
+                                   PROP_ACTIVE,
+                                   g_param_spec_boolean ("active",
+                                                         "Active",
+                                                         "Whether the button persistently active",
+                                                         FALSE,
+                                                         G_PARAM_READWRITE));
+
   /**
    * ShellButtonBox:hover
    *